home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Networking / OTStreamLogViewer / LogEngine / TestLogEngine.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  4.2 KB  |  173 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        TestLogEngine.c
  3.  
  4.     Contains:    A program to display information logged to the STREAMS log module.
  5.  
  6.     Written by: Quinn "The Eskimo!"    
  7.  
  8.     Copyright:    Copyright © 1998-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 7/23/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23.  
  24. #define qDebug 1
  25.  
  26. /////////////////////////////////////////////////////////////////////
  27. // Pick up the standard C stuff.
  28.  
  29. #include <stdio.h>
  30. #include <string.h>
  31.  
  32. /////////////////////////////////////////////////////////////////////
  33. // Pick up standard OT APIs.
  34.  
  35. #include <OpenTptInternet.h>
  36.  
  37. /////////////////////////////////////////////////////////////////////
  38. // Pick up low-level OT APIs.
  39.  
  40. #include <OpenTptClient.h>
  41. #include <OTDebug.h>
  42. #include <strlog.h>
  43. #include <stropts.h>
  44. #include <mistream.h>
  45.  
  46. /////////////////////////////////////////////////////////////////////
  47. // Pick up the symbolic name of the various OT modules.
  48.  
  49. #include <modnames.h>
  50.  
  51. /////////////////////////////////////////////////////////////////////
  52. // Pick up the log engine prototypes.
  53.  
  54. #include "LogEngine.h"
  55.  
  56. /////////////////////////////////////////////////////////////////////
  57. // OTDebugStr is not defined in any OT header files, but it is
  58. // exported by the libraries, so we define the prototype here.
  59.  
  60. extern pascal void OTDebugStr(const char* str);
  61.  
  62. /////////////////////////////////////////////////////////////////////
  63.  
  64. /////////////////////////////////////////////////////////////////////
  65.  
  66. static pascal void PrintLogEntry(LogEntryPtr thisEntry, void *refCon)
  67. {
  68.     #pragma unused(refCon)
  69.     #pragma unused(thisEntry)
  70.     
  71.     printf("••• got message “%s”\n", ((char *) thisEntry) + sizeof(LogEntry));
  72. }
  73.  
  74. /////////////////////////////////////////////////////////////////////
  75.  
  76. static void PrintHelp(void)
  77. {
  78.     printf("s) start/stop logging\n");
  79.     printf("l) log something\n");
  80.     printf("L) log 10 somethings\n");
  81.     printf("i) idle the kernel (don't ask why you have to do this!)\n");
  82.     printf("p) print new log entries\n");
  83.     printf("q) quit\n");
  84.     printf("?) print help\n");
  85.     printf("\n");
  86. }
  87.  
  88. extern void main(void)
  89. {
  90.     OSStatus err;
  91.     Boolean quitNow;
  92.     char command[256];
  93.     int i;
  94.     
  95.     printf("Hello Cruel World\n");
  96.     
  97.     err = InitOpenTransport();
  98.     if (err == noErr) {
  99.     
  100.         PrintHelp();
  101.         quitNow = false;
  102.         do {
  103.             printf("Enter command:\n");
  104.             gets(command);
  105.             switch (command[0]) {
  106.                 case '?':
  107.                     PrintHelp();
  108.                     break;
  109.                 case 's':
  110.                     if ( ! LoggingActive() ) {
  111.                         printf("StartLogging\n");
  112.                         fflush(stdout);
  113.                         err = StartLogging(true, 0, nil);
  114.                         if (err != noErr) {
  115.                             printf("Error starting logging %ld\n", err);
  116.                             err = noErr;
  117.                         }
  118.                     } else {
  119.                         printf("StopLogging\n");
  120.                         fflush(stdout);
  121.                         StopLogging();
  122.                     }
  123.                     break;
  124.                 case 'i':
  125.                     OTIdle();
  126.                     break;
  127.                 case 'p':
  128.                     ForEachNewLogEntry(PrintLogEntry, nil);
  129.                     break;
  130.                 case 'q':
  131.                     quitNow = true;
  132.                     break;
  133.                 case 'l':
  134.                     printf("Calling strlog\n");
  135.                     strlog(1, 2, 3, SL_TRACE | SL_ERROR, "Hello Cruel World!");
  136.                     break;
  137.                 case 'L':
  138.                     for (i = 0; i < 10; i++) {
  139.                         printf("Calling strlog\n");
  140.                         strlog(1, 2, 3, SL_TRACE | SL_ERROR, "Hello Cruel World!");
  141.                     }
  142.                     break;
  143.                 case '!':
  144.                     for (i = 0; i < 32000; i++) {
  145.                         // OTIdle();
  146.                         strlog(1, 2, 3, SL_TRACE | SL_ERROR, "Hello Cruel World!");
  147.                         if ( (i % 100) == 0) {
  148.                             printf(".");
  149.                             fflush(stdout);
  150.                         }
  151.                     }
  152.                     break;
  153.                 default:
  154.                     printf("Huh?\n");
  155.                     break;
  156.             }
  157.         } while ( ! quitNow );
  158.     
  159.         if ( LoggingActive() ) {
  160.             printf("StopLogging\n");
  161.             fflush(stdout);
  162.             StopLogging();
  163.         }
  164.     
  165.         CloseOpenTransport();
  166.     }
  167.     
  168.     if (err == noErr) {
  169.         printf("Success!\n");
  170.     } else {
  171.         printf("Failed with error %ld.\n", err);
  172.     }
  173. }